package com.acme.task2;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.util.LinkedList;
import java.util.Random;
import java.util.Scanner;

@SuppressWarnings("serial")
public class MyChart extends JPanel {

	private int[] data;
	private int max;

	public MyChart(int[] data, int max) {
		this.data = data;
		this.max = max;
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);

		Graphics2D g2d = (Graphics2D) g;

		Dimension size = getSize();
		Insets insets = getInsets();

		int w = size.width - insets.left - insets.right;
		int h = size.height - insets.top - insets.bottom;

		Random rand = new Random();
		for (int i = 0; i < data.length; i++) {
			double ratio = (double) data[i] / max;
			int x = (int) Math.round(ratio * w);

			float red = rand.nextFloat();
			float green = rand.nextFloat();
			float blue = rand.nextFloat();
			g2d.setColor(new Color(red, green, blue));

			g2d.drawLine(x, 0, x, h);
		}
	}

	public static void main(String[] args) {
		// Read input
		Scanner scanner = new Scanner(System.in);
		LinkedList<Integer> input = new LinkedList<Integer>();
		while (scanner.hasNextLine()) {
			int x = Integer.parseInt(scanner.nextLine());
			input.add(x);
		}

		int max = input.get(0);
		int[] data = new int[input.size()];
		for (int i = 0; i < input.size(); i++) {
			int current = input.get(i);
			data[i] = current;
			if (current > max) {
				max = current;
			}
		}

		scanner.close();
		System.out.println(max);

		// Show chart
		JFrame frame = new JFrame("Chart");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(new MyChart(data, max));
		frame.setSize(1200, 200);
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
	}
}
